home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / TABCNTRL.PAK / DISPATCH.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  169 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   dispatch.c
  9. //
  10. //  PURPOSE:  Implement the generic message and command dispatchers.
  11. //    
  12. //
  13. //  FUNCTIONS:
  14. //    DispMessage - Call the function associated with a message.
  15. //    DispCommand - Call the function associated with a command.
  16. //    DispDefault - Call the appropriate default window procedure.
  17. //
  18. //  COMMENTS:
  19. //
  20.  
  21. #include <windows.h>            // required for all Windows applications
  22. #include <windowsx.h>
  23. #include "globals.h"            // prototypes specific to this application
  24.  
  25. LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
  26. extern  HWND hwndTabControl;
  27.  
  28. //
  29. //  FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
  30. //
  31. //  PURPOSE: Call the function associated with a message.
  32. //
  33. //  PARAMETERS:
  34. //    lpmsdi - Structure containing the message dispatch information.
  35. //    hwnd - The window handle
  36. //    uMessage - The message number
  37. //    wparam - Message specific data
  38. //    lparam - Message specific data
  39. //
  40. //  RETURN VALUE:
  41. //    The value returned by the message function that was called.
  42. //
  43. //  COMMENTS:
  44. //    Runs the table of messages stored in lpmsdi->rgmsd searching
  45. //    for a message number that matches uMessage.  If a match is found,
  46. //    call the associated function.  Otherwise, call DispDefault to
  47. //    call the default function, if any, associated with the message
  48. //    structure.  In either case, return the value recieved from the
  49. //    message or default function.
  50. //
  51.  
  52. LRESULT DispMessage(LPMSDI lpmsdi, 
  53.                     HWND   hwnd, 
  54.                     UINT   uMessage, 
  55.                     WPARAM wparam, 
  56.                     LPARAM lparam)
  57. {
  58.      int  imsd;
  59.  
  60.     MSD *rgmsd = lpmsdi->rgmsd;
  61.     int  cmsd  = lpmsdi->cmsd;
  62.  
  63.     for (imsd = 0; imsd < cmsd; imsd++)
  64.     {
  65.         if (rgmsd[imsd].uMessage == uMessage)
  66.             return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
  67.     }
  68.  
  69.     return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
  70. }
  71.  
  72. //
  73. //  FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
  74. //
  75. //  PURPOSE: Call the function associated with a command.
  76. //
  77. //  PARAMETERS:
  78. //    lpcmdi - Structure containing the command dispatch information.
  79. //    hwnd - The window handle
  80. //    GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
  81. //      control, or accelerator.
  82. //    GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
  83. //    GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
  84. //
  85. //  RETURN VALUE:
  86. //    The value returned by the command function that was called.
  87. //
  88. //  COMMENTS:
  89. //    Runs the table of commands stored in lpcmdi->rgcmd searching
  90. //    for a command number that matches wCommand.  If a match is found,
  91. //    call the associated function.  Otherwise, call DispDefault to
  92. //    call the default function, if any, associated with the command
  93. //    structure.  In either case, return the value recieved from the
  94. //    command or default function.
  95. //
  96.  
  97.  
  98. LRESULT DispCommand(LPCMDI lpcmdi, 
  99.                     HWND   hwnd, 
  100.                     WPARAM wparam, 
  101.                     LPARAM lparam)
  102. {
  103.      WORD    wCommand = GET_WM_COMMAND_ID(wparam, lparam);
  104.      int     icmd;
  105.  
  106.     CMD    *rgcmd = lpcmdi->rgcmd;
  107.     int     ccmd  = lpcmdi->ccmd;
  108.  
  109.     // Message packing of wparam and lparam have changed for Win32,
  110.     // so use the GET_WM_COMMAND macro to unpack the commnad
  111.  
  112.     for (icmd = 0; icmd < ccmd; icmd++)
  113.     {
  114.         if (rgcmd[icmd].wCommand == wCommand)
  115.         {
  116.             return rgcmd[icmd].pfncmd(hwnd,
  117.                                       wCommand,
  118.                                       GET_WM_COMMAND_CMD(wparam, lparam),
  119.                                       GET_WM_COMMAND_HWND(wparam, lparam));
  120.         }
  121.     }
  122.  
  123.     return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
  124. }
  125.  
  126.  
  127. //
  128. //  FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
  129. //
  130. //  PURPOSE: Call the appropriate default window procedure.
  131. //
  132. //  PARAMETERS:
  133. //    edwp - Enumerate specifying the appropriate default winow procedure.
  134. //    hwnd - The window handle
  135. //    uMessage - The message number
  136. //    wparam - Message specific data
  137. //    lparam - Message specific data
  138. //
  139. //  RETURN VALUE:
  140. //    If there is a default proc, return the value returned by the
  141. //    default proc.  Otherwise, return 0.
  142. //
  143. //  COMMENTS:
  144. //    Calls the default procedure associated with edwp using the specified
  145. //    parameters.
  146. //
  147.  
  148. LRESULT DispDefault(EDWP   edwp, 
  149.                     HWND   hwnd, 
  150.                     UINT   uMessage, 
  151.                     WPARAM wparam, 
  152.                     LPARAM lparam)
  153. {
  154.     switch (edwp)
  155.     {
  156.         case edwpNone:
  157.             return 0;
  158.         case edwpWindow:
  159.             return DefWindowProc(hwnd, uMessage, wparam, lparam);
  160.         case edwpDialog:
  161.             return DefDlgProc(hwnd, uMessage, wparam, lparam);
  162.         case edwpMDIFrame:
  163.             return DefFrameProc(hwnd, hwndMDIClient, uMessage, wparam, lparam);
  164.         case edwpMDIChild:
  165.             return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
  166.     }
  167.     return 0;
  168. }
  169.